<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // 递归函数：函数内部自己调用自己
        // 阶乘
        function jiecheng(n){
            if(n == 1){
                return 1;
            }
            return n * jiecheng(n - 1);
        }

        var total = jiecheng(3);
        console.log(total);

        // 斐波那契数列
        function fb(n){
            if(n === 1 || n === 2){
                return 1;
            }
            return fb(n - 1) + fb(n -2);
        }
        var fb = fb(5);
        console.log(fb);

        var data = [
            {
                id: 1,
                name: '家电',
                goods: [
                    { id: 11, gname: '冰箱' },
                    { id: 12, gname: '洗衣机' }
                ]
            },
            {
                id: 2,
                name: '服饰'
            }
        ]
        // 我们想要做输入id号，就可以返回的数据对象
        function bl(n, data){
            for(var i = 0; i < data.length; i++){
                if(data[i].id == n){
                    return data[i];
                }
                if(data[i].hasOwnProperty('goods') && data[i].goods != null){
                    return bl(n, data[i].goods)
                }
            }
        }
        var n = bl(11, data);
        console.log(n);
    </script>
</body>
</html>